<?php 
header("Content-Type: text/html; charset=utf-8");
session_start();
if (!isset ($_SESSION["id"])) {
	session_destroy();
	echo "<script language='javascript'>top.location.href = 'Login.php';</script>";
	exit;
}

include_once 'public/DB_Oracle.php';
include_once 'public/page/page.class.php';
$DBsql = new DB_Oracle ();
//查询所有的派出所
$sql="select dd.department_index, dd.department_name
		  from dep_department dd
		 order by dd.department_index";
$dedp=$DBsql->fetch_all_array($sql);
if(empty($_GET['departmentID'])){
	//查询所以警员
	$sql="select dp.personnel_index from dep_personnel dp";
	$rows=$DBsql->fetch_all_array($sql);
	$pageSize = 12;
	$total=count($rows)== 0 ? 1 : count($rows);
	//第一个0显示数字  第二个1显示概况 第三个显示下拉 第四个显示数字数量
	pageft($total, $pageSize, 1, 1, 1, 5);
	$displaypg+=$firstcount;
	$sql="select *
		  from (select rownum r,
	               dp.personnel_index,
	               dp.personnel_name,
	               (case
				         when dp.personnel_gender = 1 then
				          '男'
				         else
				          '女'
				       end) personnel_gender,
	               dp.personnel_sn,
	               dd.department_name,
	               dp.DEVICE_ID
	          from dep_personnel dp, dep_department dd
	         where dp.department_index = dd.department_index
	         order by dp.personnel_index) c
		 where c.r > $firstcount
		   and c.r <= $displaypg";
	$rows=$DBsql->fetch_all_array($sql);
}else{
	$depID=$_GET['departmentID'];
	//查询所以警员
	$sql="select dp.personnel_index from dep_personnel dp where dp.department_index=$depID";
	$rows=$DBsql->fetch_all_array($sql);
	$pageSize = 12;
	$total=count($rows)== 0 ? 1 : count($rows);
	//第一个0显示数字  第二个1显示概况 第三个显示下拉 第四个显示数字数量
	pageft($total, $pageSize, 1, 1, 1, 5);
	$displaypg+=$firstcount;
	$sql="select *
		  from (select rownum r,
	               dp.personnel_index,
	               dp.personnel_name,
	               (case
				         when dp.personnel_gender = 1 then
				          '男'
				         else
				          '女'
				       end) personnel_gender,
	               dp.personnel_sn,
	               dd.department_name,
	               dp.DEVICE_ID
	          from dep_personnel dp, dep_department dd
	         where dp.department_index = dd.department_index
	         and dp.department_index=$depID
	         order by dp.personnel_index) c
		 where c.r > $firstcount
		   and c.r <= $displaypg";
	$rows=$DBsql->fetch_all_array($sql);
}
?>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/validform.css" rel="stylesheet" type="text/css" />
<link href="public/page/css/css.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="js/Validform.js"></script>
<script language="javascript" type="text/javascript" src="js/public.js"></script>
<script language='javascript'><!--
var flag=false;
	function sltItem(e){
		if(e.checked){
			document.getElementById("hidd").value+=",";
			document.getElementById("hidd").value+=e.value;
		}else{
			var str=document.getElementById("hidd").value;
			var checkValu=","+e.value;
			var valu=str.replace(checkValu,"");
			document.getElementById("hidd").value=valu;
		}
	}
	function setselectstate(){
		   if(flag){
			   var $aray = document.getElementsByName("selectID");
			   for(var i=0;i<$aray.length;i++){
						$aray[i].checked = false;
				}
			   flag=false;
		   }else{
			   var $aray = document.getElementsByName("selectID");
			   for(var i=0;i<$aray.length;i++){
						$aray[i].checked = true;
				}
				flag=true;
		   }
		   sltAll();
		}
	function sltAll(){
		var $aray = document.getElementsByName("selectID");
		var $str="";
		var sub=",";
		for(var i=0;i<$aray.length;i++){
			if($aray[i].checked){
				$str+=sub+$aray[i].value;
			}
		}
		if($str==","){
			$("#hidd").val("");
		}else{
			$("#hidd").val($str);
		}
	}
	function delChecked(){
		var id=$('#hidd').val();
		if(id==""){
			alert('请选择要删除的人员');
		}else{
			sn=id.substr(1,id.length);
			delRow(sn);
		}
	}
	//新建警员
	function POP(popDiv){
		POPdiv(popDiv);
		$('#add').focus();
	}
	//修改警员信息
	function editRow(rowId){
		$.ajax({
			type:'POST',
			url:'manageUser.php',
			data:'act=select&sn='+rowId,
			dataType:'json',
			beforeSend:function(){
				$('#userNumUp').val('');
				$('#userNameUp').val('');
				$('#workUp').val('');//派出所
				$("input[name='genderUp'][value=1]").attr("checked",true); //性别
				$('#hidd').val('');//用于修改警员的id
				$('#userNoUp').val('');//手持设备编号
			},
			success:function(data){
				$('#userNumUp').val(data[3]);//警号
				$('#userNameUp').val(data[1]);//姓名
				$('#workUp').val(data[5]);//派出所
				$("input[name='genderUp'][value="+data[2]+"]").attr("checked",true); //性别
				$('#hiddUp').val(data[0]);//用于修改警员的id
				$('#userNoUp').val(data[6]);//手持设备编号
			},
			error:function(){
				alert('服务器繁忙！');
			},
			complete:function(){
				POPdiv('UPdiv');
				$('#up').focus();	
			}
		});
	}
	//删除区号信息
	function delRow(rowId){
		if(!confirm('您确定删除该用户信息吗？')){
			return false;
		}
		$.ajax({
			type:'POST',
			url:'manageUser.php',
			data:'act=del&sn='+rowId,
			success:function(data){
				if(data=='y'){
					$.Showmsg('删除成功！');
					setTimeout(function(){
					$.Hidemsg();
					window.location.reload();
				},1000);
				}else{
					$.Showmsg('删除失败！');
				}
			}	
		});
	}
	
	$(function(){
		$("#adduser").Validform({
			 tiptype:2,
			   ajaxurl:"manageUser.php?act=add",
			   callback:function(data){
					if(data.status=="y"){
						$.Showmsg(data.info);
						setTimeout(function(){
							$.Hidemsg();
							window.location.reload();
						},1000);
					}else{
						$.Showmsg(data.info);
					}
			   }
		});
	$("#upuser").Validform({
		 tiptype:2,
		   ajaxurl:"manageUser.php?act=up",
		   callback:function(data){
				if(data.status=="y"){
					$.Showmsg(data.info);
					$.Showmsg(data.info);
					setTimeout(function(){
						$.Hidemsg();
						window.location.reload();
					},1000);
				}else{
					$.Showmsg(data.info);
				}
		   }
	});
});
//获取双击页面事件
document.ondblclick = function(){
	//$("#selectID").val('');
	POPdiv('selectLocation');
};
function groupSelect(){
	var policeID=$("#selectID").val();
	$('#departmentID').val(policeID);
	$('#Location').submit();
}
--></script>
<!--管理列表开始-->
<div class="manageTab">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="usrTab">
    <tr>
      <td width="8" height="25"><img src="images/user_01.jpg" height="25" width="8" /></td>
      <td style="background:#3980b2;" valign="middle" height="16" ><div class="use_righgDiv"><span>
        <input type="checkbox" id="checkall" name="" value="" onclick="setselectstate()" />
        全选</span><span><img src="images/001.gif" height="14" width="14" /><a href="javascript:void(null)" onclick="POP('POPdiv');">新增</a></span><span><img src="images/114.gif" height="14" width="14" /><a onclick="delChecked()" href="javascript:void(null)">批量删除</a></span><span></span></div>
        <div class="use_leftDiv">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td  width="22"><img src="images/311.gif" height="16" width="16" /></td>
              <td align="left"><span class="tdTit">用户管理列表</span></td>
            </tr>
          </table>
        </div></td>
      <td width="8" height="25"><img src="images/user_02.gif" height="25" width="8" /></td>
    </tr>
    <tr>
      <td style="background:#3980b2;" >&nbsp;</td>
      <td>
        <table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" class="usrList" id="List">
          <tr>
            <td width="5%" class="td90b2">选择</td>
            <td width="9%" class="td90b2">编号</td>
            <td width="9%" class="td90b2">姓名</td>
            <td width="9%" class="td90b2">性别</td>
            <td width="14%" class="td90b2">单位</td>
            <td width="15%" class="td90b2">人员号</td>
            <td width="15%" class="td90b2">手持设备编号</td>
            <td width="8%" class="td90b2">编辑</td>
            <td width="8%" class="td90b2">删除</td>
          </tr>
          <?php if(count($rows)!=0){
          		foreach ($rows as $ros){
          	?>
	          <tr id="List1">
	            <td class="tdfff"><input type='checkbox' onclick='sltItem(this)' name="selectID" class="STYLE2" value="<?php echo $ros['PERSONNEL_INDEX'];?>" /></td>
	            <td class="tdfff"><?php echo $ros['PERSONNEL_INDEX'];?></td>
	            <td class="tdfff"><?php echo $ros['PERSONNEL_NAME'];?></td>
	            <td class="tdfff"><?php echo $ros['PERSONNEL_GENDER'];?></td>
	            <td class="tdfff"><?php echo $ros['DEPARTMENT_NAME'];?></td>
	            <td class="tdfff"><?php echo $ros['PERSONNEL_SN'];?></td>
	            <td class="tdfff"><?php echo $ros['DEVICE_ID'];?></td>
	            <td class="tdfff"><div align="center"><img src="images/037.gif" width="9" height="9" /><span class="STYLE1"> [</span><a href="javascript:void(null)" onclick="editRow('<?php echo $ros['PERSONNEL_INDEX'];?>')">编辑</a><span class="STYLE1">]</span></div></td>
	            <td class="tdfff"><div align="center"><img src="images/010.gif" width="9" height="9" /><span class="STYLE1"> [</span><a href="javascript:void(null)" onclick="delRow('<?php echo $ros['PERSONNEL_INDEX'];?>')">删除</a><span class="STYLE1">]</span></div></td>
	          </tr>
          <?php }}else{echo '暂无数据！';}?>
          <tr>
            <td colspan="9" class="tdfff">&nbsp;</td>
          </tr>
        </table>
      </td>
      <td style="background:#3980b2;">&nbsp;</td>
    </tr>
    <tr>
    	 <td height="28" width="8"><img src="images/user_03.gif" height="28" width="8" /></td>
    <td style="background:#3980b2;">
    <div class="green-black" style=""><?php echo $pagenav;?></div>
	</td>
    <td height="28" width="8"><img src="images/user_04.gif" height="28" width="8" /></td>
    </tr>
  </table>
</div>
<!--管理列表结束-->
<input type="hidden" id='hidd' value="" />
<!--弹出层新建用户开始-->
      <div id="POPdiv" class="POPdiv">
        <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('POPdiv')"><img src="images/ico_close.jpg" alt="关闭" /></a>增加人员</div>
        <div class="POPdiv_content">
			<form class="adduser" id="adduser">
			  <table border="0" cellpadding="5" cellspacing="0">
			    <tr>
			      <td width="80"><label for="userNum">人员号：</label></td>
			      <td><input type="text" ajaxurl="manageUser.php?act=valid" id="userNum" name='userNum' datatype="*" nullmsg="请输入人员号" errormsg='至少3~10个字符'/></td>
			      <td><span class="Validform_checktip">至少3~10个字符</span></td>
			    </tr>
			    <tr>
			      <td width="80"><label for="userName">姓名：</label></td>
			      <td><input type="text" name='userName' id="userName" datatype="s" nullmsg="请输入人员姓名" errormsg='至少2~4个字符'/></td>
			      <td><span class="Validform_checktip">至少2~4个字符</span></td>
			    </tr>
			    <tr>
			      <td width="80"><label for="userSex">性别：</label></td>
			      <td>
			      	<input type="radio" value="1" checked="checked" name="gender" id="male" datatype="radio" errormsg="请选择性别！" /> 男
			      	<input type="radio" value="2" name="gender" id="female" /> 女
			      	</td>
			      <td><span class="Validform_checktip"></span></td>
			    </tr>
			    <tr>
			      <td width="80"><label for="userNo">手持编号：</label></td>
			      <td>
			      	<input type="text" name='userNo' id="userNo" datatype="s" nullmsg="请输入手持设备编号" errormsg='至少6~10个字符'/>
			      </td>
			      <td><span class="Validform_checktip"></span></td>
			    </tr>
			    <tr>
			      <td width="80"><label for="work">所在单位：</label></td>
			      <td><select id="work" name='work' datatype='select' errormsg='请选择派出所'>
			          <option value="">选择单位</option>
			          <?php 
			          	foreach ($dedp as $row){
			          		echo "<option value='".$row['DEPARTMENT_INDEX']."'>".$row['DEPARTMENT_NAME']."</option>";
			          	}
			          ?>
			        </select></td>
			      <td><span class="Validform_checktip"></span></td>
			    </tr>
			    <tr>
			      <td colspan="3"><input name="" id="add" type="submit" class="btnbg" value="添加用户" style="width:70px; margin-left:80px; color:#FFF" /></td>
			    </tr>
			  </table>
			</form>
        </div>
      </div>
<!--弹出层新建用户结束-->


<!--弹出层修改用户开始-->
      <div id="UPdiv" class="POPdiv">
        <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('UPdiv')"><img src="images/ico_close.jpg" alt="关闭" /></a>修改人员信息</div>
        <div class="POPdiv_content">
          <form class="adduser" id="upuser">
			  <table border="0" cellpadding="5" cellspacing="0">
			    <tr>
			      <td width="80"><label for="userNumUp">人员号：</label></td>
			      <td><input type="text" id="userNumUp" name='userNumUp' datatype="*" nullmsg="请输入人员号" errormsg='至少3~10个字符'/></td>
			      <td><span class="Validform_checktip">至少3~10个字符</span></td>
			    </tr>
			    <tr>
			      <td width="80"><label for="userNameUp">姓名：</label></td>
			      <td><input type="text" name='userNameUp' id="userNameUp" datatype="s" nullmsg="请输入人员姓名" errormsg='至少2~4个字符'/></td>
			      <td><span class="Validform_checktip">至少2~4个字符</span></td>
			    </tr>
			    <tr>
			      <td width="80"><label for="userSex">性别：</label></td>
			      <td>
			      	<input type="radio" value="1" checked="checked" name="genderUp" id="mal" datatype="radio" errormsg="请选择性别！" /> 男
			      	<input type="radio" value="2" name="genderUp" id="femal" /> 女</td>
			      <td><span class="Validform_checktip"></span></td>
			    </tr>
			     <tr>
			      <td width="80"><label for="userNoUp">手持编号：</label></td>
			      <td>
			      	<input type="text" name='userNoUp' id="userNoUp" datatype="*" nullmsg="请输入手持设备编号" errormsg='至少6~10个字符'/>
			      </td>
			      <td><span class="Validform_checktip"></span></td>
			    </tr>
			    <tr>
			      <td width="80"><label for="workUp">所在单位：</label></td>
			      <td><select id="workUp" name='workUp' datatype='select' errormsg='请选择派出所'>
			          <option value="">选择单位</option>
			           <?php 
			          	foreach ($dedp as $row){
			          		echo "<option value='".$row['DEPARTMENT_INDEX']."'>".$row['DEPARTMENT_NAME']."</option>";
			          	}
			          ?>
			        </select></td>
			      <td><span class="Validform_checktip"></span></td>
			    </tr>
			    <tr>
			      <td colspan="3"><input name="" id="up" type="submit" class="btnbg" value="修改用户" style="width:70px; margin-left:80px; color:#FFF" /></td>
			    </tr>
			  </table>
			  <input type="hidden" id="hiddUp" name="hiddUp"/> 
			</form>
        </div>
      </div>
<!--弹出层修改用户结束-->
<!--弹出层选择派出所开始-->
<div id="selectLocation" class="POPdiv">
	 <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('selectLocation')"><img src="images/ico_close.jpg" alt="关闭" /></a>分组查看</div>
        <div class="POPdiv_content">
        	<form id="Location" action="user.php" method="get">
	        	 <table border="0" cellpadding="5" cellspacing="0">
				    <tr>
				      <td width="80"><label for="selectID">选择派出所</label></td>
				      <td>
					  	<select id="selectID" name="selectID" onchange="groupSelect()">
							<option value="">全部</option>
							 <?php 
					          	foreach ($dedp as $row){
					         ?>
					         	<option <?php if(isset($_GET['departmentID'])){if($_GET['departmentID']==$row['DEPARTMENT_INDEX']){echo 'selected=selected';}}?> value="<?php echo $row['DEPARTMENT_INDEX'];?>"><?php echo $row['DEPARTMENT_NAME'];?></option>	
					         <?php
					          	}
					         ?>
						</select>
					  </td>
				      <td><input type="hidden" id="departmentID" name="departmentID" value=""></td>
				    </tr>
				 </table>
			 </form>
		</div>
</div>
<!--弹出层选择派出所结束-->